package com.ruoyi.system.service.project.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.project.patent.PatentAuthorization;
import com.ruoyi.system.mapper.project.PatentAuthorizationMapper;
import com.ruoyi.system.service.project.IPatentAuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.ruoyi.common.utils.SecurityUtils.getUserId;

/**
 * 专利授权Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@Service
public class PatentAuthorizationServiceImpl implements IPatentAuthorizationService
{
    @Autowired
    private PatentAuthorizationMapper patentAuthorizationMapper;

    /**
     * 查询专利授权
     * 
     * @param id 专利授权主键
     * @return 专利授权
     */
    @Override
    public PatentAuthorization selectPatentAuthorizationById(Long id)
    {
        return patentAuthorizationMapper.selectPatentAuthorizationById(id);
    }

    /**
     * 查询专利授权列表
     * 
     * @param patentAuthorization 专利授权
     * @return 专利授权
     */
    @Override
    public List<PatentAuthorization> selectPatentAuthorizationList(PatentAuthorization patentAuthorization)
    {
        //如果是老师，则只显示自己上传的
        if(patentAuthorization.getCurrentRole()!=null&&patentAuthorization.getCurrentRole().equals("teacher")){
            patentAuthorization.setTeacherId( getUserId()) ;
        }
        //如果是部门，则显示老师是系里的所有
        if(patentAuthorization.getCurrentRole()!=null&&patentAuthorization.getCurrentRole().equals("department")){
            patentAuthorization.setDeptId(SecurityUtils.getDeptId());
        }
        return patentAuthorizationMapper.selectPatentAuthorizationList(patentAuthorization);
    }

    /**
     * 新增专利授权
     * 
     * @param patentAuthorization 专利授权
     * @return 结果
     */
    @Override
    public int insertPatentAuthorization(PatentAuthorization patentAuthorization)
    {
        return patentAuthorizationMapper.insertPatentAuthorization(patentAuthorization);
    }

    /**
     * 修改专利授权
     * 
     * @param patentAuthorization 专利授权
     * @return 结果
     */
    @Override
    public int updatePatentAuthorization(PatentAuthorization patentAuthorization)
    {
        return patentAuthorizationMapper.updatePatentAuthorization(patentAuthorization);
    }

    /**
     * 批量删除专利授权
     * 
     * @param ids 需要删除的专利授权主键
     * @return 结果
     */
    @Override
    public int deletePatentAuthorizationByIds(Long[] ids)
    {
        return patentAuthorizationMapper.deletePatentAuthorizationByIds(ids);
    }

    /**
     * 删除专利授权信息
     * 
     * @param id 专利授权主键
     * @return 结果
     */
    @Override
    public int deletePatentAuthorizationById(Long id)
    {
        return patentAuthorizationMapper.deletePatentAuthorizationById(id);
    }
}
